package mysqlinit

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId      int     `gorm:"type:int(11);not null commit:用户ID"`
	HouseId     int     `gorm:"type:int(11);not null commit:房源ID"`
	OrderSn     string  `gorm:"type:varchar(36);not null commit:订单编号"`
	Amount      float64 `gorm:"type:decimal(10,2);not null commit:订单金额"`
	PayType     int     `gorm:"type:tinyint(1);default:1;not null commit:1 支付宝 2 微信 银联"`
	OrderStatus int     `gorm:"type:tinyint(1);default:1;not null commit:1 未支付 2 已支付 3支付失败"`
}

func (o *Order) CreateOrder() error {
	return DB.Debug().Create(&o).Error
}
func (o *Order) FindOrder(houseId int64) error {
	return DB.Debug().Where("id = ?", houseId).Find(&o).Error
}
func (o *Order) UpdateOrder(orderSn string, orderStatus int64) error {
	return DB.Debug().Model(&o).Where("order_sn = ?", orderSn).Update("order_status", orderStatus).Error
}
